Miscellaneous cleanup

* Remove unnecessary casts
* Remove unnecessary boxing/unboxing
* Replace for with for each
* Remove more cruft