Fix #11

Fix #11 and a few more improvements.