error handling, bug fixes