Moved some error-handling to exceptions