Combined prior functions into one recurisve one and added saving functions
bug gix