fix portability problem, remove sorting dependency on memory address
correct prototypes
rename symbols to more suitable names
cleanup code