Refactor paint() to improve readability

Change-Id: Ia1f8563c5764a877bc5c5693a869d89f0229add8