adding implementation of mode function