Added documentation and improved functionality