Added log file, fixed forking and STD control