some code cleanup/refactoring