refactor: optimize memory usage; insert debug points