Added edge case error handling