Handle negative numbers. Add tracing function. Miscellaneous fixes.