Refactor update_query