added rough support for ordering layers by weight