code cleanup, and reorginization