clean up output and add logging in optimizer