Bug fixes; added more doctests