refactoring and cleanups