added some consts and adjusted, more stable now. also prevents multiple dailogs