fixed error handling; removed unused defs