Made this more safe (haven't tested for errors)