Fixes #4 and other improvements

Sorry, but contributors are usually not listed as authors.