sort of fixes the nullpointer exceptions but this needs to be properly done!