Tweaked api.py for better update performance