assemble function refactored