Cherrypicking commits by @happyDemon. Closes #316.

Signed-off-by: Ben Corlett <bencorlett@me.com>