Seems to work (only tested with empty shr_list)
Tested successfully with valgrind
Removed debugging printfs
Added comments