Moved redundant code to function
Merge pull request #1 from JosephKiranBabu/master

Moved redundant code to function