worked out drawAB function