started backtracking and better front end with timeout function