Merges changes by @nolith from #370 to master