debug mode added memory monitoring