-i flag support and a bunch of minor fixes