Cleaned up functions and added try-catch for missing datafile or broken internet connectoin