Implement FIRST AQL function and do some minor refactoring.
Refactor AQL query construction process to get rid of all those contexts when query is deeply nested.