Moved drawInLayer function