fixed a bug i created with the last commit related to remaining[] array