created helper functions for mode method