Added documentation and removed redundant code