eliminated redundant computations. fixed #4