Looks like working - confirmed up to n=8 queens.
Absolutely dirty, a lot of dead code to be removed.