Resolved null reference error in Key dispose function