Changed from heap array to stack array.
Fixed ugly code.