Refactored modal implementation