refactoring modal code to have more assertive tests