v0.4.0

Some refactors by @jasonLaster and other code cleanups.