cleanup & some refactoring