Minor variable tweaks and added/modified functions as per L. Lewis advice.