Backend logic

Merge Josh's Code