ADDED: check to avoid java.lang.OutOfMemory errors