[REFACTOR] Added support for specifying a query and a daily/monthly opti...

...on at the backend script