Changed code to c as it seems a lot more stable. Removed all python code