Added more tests, fixed code according to them.