cleanup and minor refactor