The code translated from original is a bit messy.
Activity