added debug mode. purged useless to_hash and to_json functions all over