Reformatted, and added numerous new functions