[issue547] remove flakes and pep issues; add tests