minor code cleanup and general improvements