Added promises and deferral to JS