Refactor CLI implementation, resolves #27 and #28