Updated to correctly encode range