added local arrays and fixed some issues