attempt to fix endless loop(mostly unsuccessfully)