Fixing undefineds in a very poor way, but it works