reduced some global references
added some kludgy mouse detection