[PATCH 00/20] code cleanup and minor bug fixes