I see you didn't added the isinstance checks. Is this working for you in all cases? Don't have xbmc at work to check.