Add logging and implement timeoutthread