Lots of small changes, fix #46.