code refactoring and cleanups