Refactor dialog-related functions into a separate file