code cleanup and duplicate code removal
Merge remote-tracking branch 'origin/master'