Cleaned up code a bit, made chained api calls less hacky