Cleanup

* code cleanup
* minor speed improvements