Major refactoring of backend, 30% less db queries, remove logic duplication