Completed inital code for query and display