added encoding on background and decoding and logging on foreground