some restructuring and tests