Code cleanup and prep for testing