Refactor #703 #336