improved modularization
now the main diff function is less script-like