yeah, this is a direct port from the old code. I tried not to make too many changes in this round.