Fixed naming, logic issues, and mishandled or unhandled error cases.