root function working correctly