Complete rewrite, with rdoc and no rubocop offences