cleanup & minor refactoring