Clean up whitespace

It's a big patch but it's purely a clean up, removed trailing whitespace from the end of lines and converted all hard tabs to four spaces to make the code more consistent.