refactored a portion of code involving negIndex (~line 300)