code refactor for final submission