Refactored crawling functions and added socket closes()