bugfix + better error handling