properly implement to_json