moving bulk of code out of glove into own files and into lib dir