Modified rangetotable and added rangetoverticaltable functions