Added logic to elliminate duplication of code. Closes #7