Added some tests and refactored others