Refactoring and general clean up.