Refactor duplicate codes [issue#50].

Signed-off-by: Dhananjay Nakrani <dhananjaynakrani@gmail.com>
Merge pull request #51 from dhananjay92/dhananjay-gsoc-issue#50

Refactor duplicate codes [issue#50].