Moved logic into api.py.
expanded test.py
few minor tweaks