code cleanup, starting refactoring