Just a remark: your indentation style (or lack thereof) sucks; it is extremely difficult to see the flow of control or where blocks start or end; for your own sake improve your indents. IDEs can do that for you.