Fixed condition error.
Updated with link to Gists.