better implementation of max run  time