Modified according to comments in pull-request discussion.