Improve query code including save state, use prop