New getmirror optimized function and some fixes
Add comments and clean up.