added function for negative numbers
Numbers larger than 1000 are ignored
Factored code for largenumbers