Some sonar issues fixed:

- log the occurred exception
- use curly braces
- don't use literals like "true" or "false" in condition statement

+ port counting up to a certain limit to omit infinite loop

Signed-off-by: Nico Rutishauser <nr@hotmail.ch>