fixing api queries and some DB stuff