Fixed logic and shell command to remove whitespace