Implements the cleanup process of sequence number.

Such mechanism follows the specified on RFC 4340#7.2

Signed-off-by: Ivo Calado <txithihausen@gmail.com>
Signed-off-by: João Correia <lucaskm98@gmail.com>
Fix minor bugs in the previous commit
Signed-off-by: Ivo Calado <txithihausen@gmail.com>