Reformatted code, fixed issues