moved the error handling and dictionary check to it's own method