Clean-up: Removal of experimental code.
Adding missing generic type parameters.
Locally scoping index variables.
Compacting and reformatting code.