Totally refactored code.  Should work better now.