cleaned code to have api.py make more sense