Fixing some queries and adding small API