Loop optimization + fixed offset bug.
Refactor junits
Throw ClosedException instead of IllegalStateException