On boundary terms and conformal transformations in curved spacetimes