Added more tests, fixed more bugs