Fixed memory corruption in drawdots() and cleaned code up a bit