clean, comment and refactor libs based on main.py