Added code to avoid none-type exceptions.