Library template nesting fixes

See comments on https://github.com/hummingbird-me/hummingbird/commit/edae9be4eea0717f2c5ccd253c9a09df2d9cbdd2 for info