Now that #268 has been merged, this need some refactoring as well