code cleanup and improvement