added all API calls and cleaned up code