cleanup and refactor tests