Aside from a full rewrite this is probably the best you are going to get