Updated painted event to  trigger only once