Added corner case error handling