small refactor flags, add lgtm, refactor code