many tests added, bugs found from tests fixed