Upstream

Added Layer Sorting and some minor bug fixes