Added new tests and cleaned up code