Fix use of pkg-config; refactor