add tests and implement fixes