Properly handle aggragates in operations

Made operations with aggregates work

Also fixed a bug in aggregates for array