Changed to quadratic version to get rid of paint errors