Changed error checking. moved keys to constants.