Some improvements

Replaced alerts with console.log and made splice loop through elements