Fixed a broken query in DB, fixed behaviour when no data in table also