Added tests and implementation for handling negative numbers