some restructuring before merging