refactored and added some queries