Switched most functions over to NumPy for efficiency