Refactor + more tests