Changed identifiers and moved several things into their own functions