Add timeout

Note: a timeout has been added to solve a stability issue. Please note
that this version has not been fully tested yet.