Fixed bug in ranges

Fixed issue #164.