Fixed some bugs, mostly related to invalid entries
Refactored tests; added tests on invalid inputs