fixed g++ compile issues and missing return statement in a free function.