add tests and fix found bug