refactoring and simplifying, making functions more like the api