Cleanup code and minor fixes in docs