Major rewrite - 2x speed improvement!

Major rewrite - 2x speed improvement!