code refactoring and added timeout to ss.accept()