refactors to clean up code in a variety of places