Various minor cleanups and buglet fixes. Reviewed by Akshay Joshi.