Added some documentation and efficiency improvements