code cleanup/merge part 1