build fixes, minor performance improvements, comments, refactorings