Handle errors more effectively
Fix #48 and #47