Fix #6, also correctly reimplemented #3.