Changing logic with DB and queries