Modal improvements and refactoring.