refactored python to be rpython compatible