Tests and Refactoring