Refactored api implementation from Philip