Complete rewrite. Merged two tools into single one.