rewrite with baselayers, and history

this is the rewrite in CoffeeScript that I mentioned in #15 if you are interested in merging it in.