You are actually not getting a black screen per say...
Your problem is that you have quite a lot of nested loops in your code.
I tried using toogle disabled on different sections of your code.
<img src="https://dl.dropboxusercontent.com/u/2560922/mobiledev/forum/nestedLoopsProblem.PNG" border="0" />
The areas where the PC really start to do a lot of work is in section 1 in the screenshot above. And it goes beyond what I wanted to wait for at least when you enable the section 2 in the screenshot above.
Its is a matter of looking at how many times you go through the array, and in the end of your nesting you are running through the array quite a lot of times.