implemented vm class, switched to it instead of bunch of global variables
deleted some unused variables