Fixed error and added try-catch to opening STDERR and STDOUT streams for logging