refactor & fix tests