Added error codes to the exceptions.
Also changed from enum to static int definitions
Merge origin/master