Fixed a number of issues.
And removed a piece of stupid code.