Tried my best to merge the two patches.