code cleanup and reorganization in new method