added some documentation and removed redundant code