Changed the entire code to be more of an API