Rearrange code and set up a config file instead of holding config in endpoints