tested and it works well for a single file, needs fine tuning for
multiple files though.