Added support for elapsed time and timeout function