Refactored code and renamed some functions
Fixed aplication read and write data to terminal

Modified also a couple of other issues with shutting down the application and signal handling. Added time to logging messages to file.