some restructuring and cleaning up