Remove unused variable

Signed-off-by: Stefan Marr <git@stefan-marr.de>
Moving variables into the closures/blocks

Signed-off-by: Stefan Marr <git@stefan-marr.de>
Use integer division instead of double division

- this is simpler and correct. And also minimizes differences with the Java version

Signed-off-by: Stefan Marr <git@stefan-marr.de>
Move temp into block where it is used

Signed-off-by: Stefan Marr <git@stefan-marr.de>
Remove dead code

Signed-off-by: Stefan Marr <git@stefan-marr.de>
Added support for sorting to OrderedCollection and sort only once

- this change is to make it easier to have similar behavior in the Java version

Signed-off-by: Stefan Marr <git@stefan-marr.de>