add tests, fixes according to review comments