Refactored (mostly equares_con). Added server mode (-s option).