Refactor + tests