Refectored api code for readability.