refactored python fold