Fixed remove_sstring() not checking the condition properly and not freeing temp.
Added a check for when there isn't enough memory.