consolidating c functions