Add timeout functions, some fixes