Cleaned code and generalized medalAjaxAPI()