added dry run option, starting moving bits into functions