Made some optimizations to the algorithm.
    * passing values rather than pointers.
    * Removed some un-needed variables here and there.