a few bugs fixed and a few tests added