rewrote source generation routine