Cleanup, strip dead code, and performance improvements