Converted code to C