refactoring code to split out libraries, etc.