Repeated issue numbers

Fix for issue #21.  Also refactored code for easier maintainability.