Refactored the modal stuff