code cleanup and merging