Apply patches from issue #6