Issue #15-Refactor code added to fix #5