Reformatting to pass (most) coding standards, and fixed issue with some function definitions