fixed bug in testing functions, changed var alloc in gradient expression