Cleanup and throw exceptions