Master phase1

Fix performance querying to database