fix a bug with negative numbers and replace stringbuffer