Fixed failing test and avoiding shared vars in anonymous class