lots of revision: simplify code; factor out and remove redundant code; some bug fixes
lots of revision: simplify code; factor out and remove redundant code; some bug fixes

gbbr/rubex,gbbr/rubex,moovweb/rubex,moovweb/rubex