added mode functions and tests