added optimization from payette.  not fully verified