adding a isKeyValid method and finishing the factory