Changed flow to throw exceptions on error instead of error codes