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

Check if connected before checking if keep-alive limit is expired