wrapping function in $(document).ready

Do not know why this is needed here.  Is there some mechanism
that normally does this?  If so, why is it broken here?