Refactored to separate cmdline tool