Added documentation. Minor performance improvement