added both mode, improved comments