Cleanup librustpkg a little bit.

Mostly I did simple transformations from imperative style loops to
more functional iterator based transformations.