Fixed the bugs while changing layering