Added code to solve the key error problem in the main dictionary