Some fixes, mostly getting rid of stupid temp square. Start of possible move to javascript.