Backend logic refactor