Fixed some layer-related bugs.