Error handling improvements and small edits