originally authored by Nick Pettit - https://github.com/nickpettit/glide