function implementation and basic test (passed)