writing some unit tests and updating the code based on that