numpy added, slowness removed

basically rewritten everything using numpy instead of long iterating
loops, vastly speeding things up and simplifying the algorithm.