code cleanup and other fine tuning