added timeout and some fixes