fixes #9, also many small improvements.