added implementation, and corrected unit tests