Logging and popt
Fix popt usage
add logging