cleaning up and minor refactoring