fixed nullpoiter exception and changed save function