switched code to c