major fix to sub-routine, still not done