Slight refactor, fix tests