First implementation

Still unfinished, but already quite usable. There is too much to
document right here, so please look in to the code or Haddock
documentation.