Fixed bugs

Fixed the bug where the last character of every word is not showing up, and also fixed the bug where the spaces are not showing up. Also wrapped all the codes in an immediate function to eliminate global variables.