add a test and refactor a bit