Changed the way the arrays are allocated, now using malloc.
Inner loop in schedule keys uses own variable now.