Reworking api.py