Refactor drawing and improve diff calculation.