refactor get range function
sync changes with blog post