Implemented a query method that's a bit better than the existing