fixing some syntax errors I introduced and a couple other small bugs with the leaveafter code