Added try-catch for invalid keys