add exception for negative numbers, refactoring