This function has a funny smell to me.  Is there no way to make it less complicated?