fix review comments and add tests