added some tests and corrected bugs identified