started refactoring modal code