Ref function length

Reduced the number of anonymous function, especially where it did not make sense to use anonymous functions. A lot of SRP refactoring. Extracted eventMask. Fixed tabbing and spaces as mentioned in gitter.

Signed-off-by: Martin Jorn Rogalla <martin@martinrogalla.com>