cleaned code to move to clean C