Added testing code, to_json() and some docstrings