Added a few more tests and made the code more robust so they pass