IMHE the best way to figure out what's wrong when you've found the relevant snippet of code is to use Edebug.
You should read the documentation to learn more about it, but basically here is my procedure:
- identify the part of the code that crashes
- instrument the code with Edebug (C-uC-M-x)
- re-execute the code and go step by step to figure out what's going on (n)
- If the problem is in another function, jump to it GOTO 2.
Iterate until you've understood the code and find a way to fix it.