Improve tests & refactor