some reshuffeling and refactoring of methods; no functionality change