Refactor function query
Small changes to work with config