handle errors properly (needs tidying) (#20)