added documentation and fix bug null reference