some minor code restructuring/cleanup.