Fixed #344 - fixed query in several build_layer() implementations.