Add portrat tool; extract common func. to library