Added onReplace to allow cleanup