Attempt to fix null pointer problems, Ole please verify if it works