minor code cleanup and bug fix