Code cleanup/refactoring