fix and improve modal handling
add initialize environment event
clean up events