Reformatted files and fixed some bugs.