connects to api
pretty intense refactoring