changed some stuff to prevent nullpointer