fix small errors and add tests