refactor and oncomplete event implementation