added provision to run once instead of endless loop