Creating Logic & Controller for Queries