Refactor of backend logic out into discrete module