bugs fixed, tests added