Functioned out some identical code
Added Comments