fix and add tests