Cleaned up code
Added test cases