Make the code more similar to the C version