Break code into smaller functions, switch to requests instead of httplib, other minor code shortening improvements