simplified
simplified
added some alerts to help with simple debug
simplified
simplified and added explanatory comments