Bug fixes and some refactoring

I started this pull request to fix a bug where the source directory is not an immediate child of templates. Got a bit carried away with refactoring. 

I've only tested this under ruby 2.0.0. i think tests will require 2.0.0 but the puppet module should still be fine with 1.8.7 (but not tested)