fix the potential errors in the codes

1. exception throws when range start or end is null;
2. missing string range type convertion;