I suggest you start out by not using the command "diff". Later, if it appears that everything you need can be put on top of diff without changing its behavior in the previous cases, then they can be joined.