code cleanup/bug fix