refactor modal functionality