some refactoring/cleanup