Factorize some functions