Applies fix from http://stackoverflow.com/a/23003180