added more error types and improved heap error handling