made shared variable volatile, more cleanup