Re-wrote my horrible...

...code in FormMain.