some safety fixes. Fix #5