Added some explanation to code