yeah this kind of handling should be moved to the `lib/` to allow easy testing, will work on another PR.