added global vars, removed inactive code