restructuring and adding some tests