a little code cleanup and reorganizing