Added Comments and tested for bugs