added option for logs to print pid + code improvements and refactoring