should now create indexes derived from reference if they do not exist, also everything is now split into bash functions, next should clean up parameters and add more checks