code cleanup/bug fixes