refactored api to be a bit more dynamic