made some comments to the code
changed error codes to better signal the iOS app and client