Added handling of negative numbers.  Minor refactoring