Added (light) error handling, and squashed a few bugs