changed to be a constructor. bound 'this' properly for a few internal functions