some refactoring & cleanup