ajax.py refactor