Changed variable name for sanity.
Fixed whitespace logic and switch.
Fix variable scope issue.
Fix string copying. Clean up variables.