Added tests and refactored classes