Bug fixes + more error handling