I posted that before I saw the new comment. I'll rewrite this part of the code.