Fix a few errors in range processing
Add cmd-main.c used for quick testing