STABLE VERSION: cleaned up output functions in c version