Fixed painting logic