Nevertheless, I've simplified things a tiny bit (removed the unnecessary try block).