Basic cleanup and refactoring of tests