[IMP] rewrite some parts
[FIX] Fix Flake8 issue