modified code

I fixed the code to work with negative numbers