Refactored the .c file