using closure for offset now (method now works kind of like an iterator in java)
algorithm can now be run parallel
code clean up