added handy diff and mid functions