Fix error, add tests