Link to curses correctly with gcc

clang is more permissive than gcc. The correct thing is to place the
libraries after the object code.
Comment a few unclear things
unstanged changes
fix merge conflict with upstream