bugfixes and add timeout logic