changed code to use ctypes