Add default keepAliveLimit - fixes #744

Duration must be at the left of SysTime in an addition

Refactored and fixed logical errors

Fixed major issues and refactored some more