Improve and add tests