There are still some minor bugs that some people run up against with my code, but you could take a look at my ULEADER command for some inspiration. The code is massive and is definitely geared toward our company standards, but I think a lot could be learned there. Pay special attention to all of the sections that Lee Mac and several others from The Swamp have contributed.
NOTE: Be sure to put the uleader.dwg file in a path that AutoCAD will search in.
As you can see, programming ULeaders is definitely not for the faint of heart and honestly I am sure that someone like Lee Mac could go through my code, add better error handling and probably cut the number of lines of code in half.
But using these methods would eliminate the issues you are having because it would eliminate the use of (command "._uleader").