changed the repainting algorithm. not really stable