Refactored the code so the queries are built with slugs