updated to include a timeout function