Adding some tests and fixing the code accordingly