Made API requests an object, moved some functions to separate lib file