refactoring backend to be more dynamic