simplified the implementation of mode