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