Error Handling and minor bugfixes