reformatted code;
changed range handling for sorted sets and list
new version