more refactoring, fixed bug where python stops responding if on pause for too long.