a few fixes with error handling