Split library and executable, minor refactor