add query option in apply, fixes #11 to refactor