take into account that memory allocation may fail
subsitute char * for void *
Clean up and reorder prototypes and functions
Simplify logic for scale specification