layers are painted not in respect to the order they were created, but grouped by the type, e.g., rput, psline, etc., This should be changed. see this example, https://mathapedia.com/sketch/228/edit parts of the image get covered up.