refactoring of modal handling