Fixing out of range bug