Refactor

Complete rewrite of the libraries and executable.