fix code factorization problems