Refactored amd closes #3