ENH: refactor + move tests