Fixed the StackOverflow error!
Added check for negative numbers!