Refactored error types, fixes in code style.