This patch was contributed by Daniel Berlin!