added documentation and fixed mode selection