fixed the bug reported by Yiye; haven't evaluated how this affects performance yet