added memory check