moved some stuff into functions to reduce code duplication
fixed dialog names