Fix an off-by-one in shell_replace
Some code clean up
Fix a memory leak in get