Added Tests and corrected problems