Refatoring and fix test