Refactored the Main() function into several sub-functions + some improvements of the IPC code.