Error handling, bug fixes