code cleanup and simplification