Grid rearrangement bug fix and animation code cleanup