Refactored source code to correct segmentation faults
and increase code maintainability.