fix a crash and small changes