Range patch from sbloom82's pull request. Reformatted to handle whitespace problems.