Fixed weird edge rendering issue.
General code tidy up.