Removed typo (spurious 'public').
Added cleared flag to prevent unnecessary re-clearing of memory.