Fixed bugs and removed trailing spaces.