Why didn't you just rewrite it? If I have 500 lines that is a mess. It's getting rewritten. If you don't understand it enough to rewrite it, then you probably don't understand it enough to even maintain or change it. In my opinion, first thing I will do is dissect it till I understand it, rewrite it and move on. 500 lines of code ain't shit. I will kill the monster before it grows.