You're using $shortfn everywhere so I can't really see why you'd get an error.

If you can narrow that script down a bit to where you think the error is people will be more willing to help you.