Reimplemented Ryan's reverted commit