bake function refactor