fixed more memory leaks, finalized window function support