Code clean up and minor refactoring.