Reformatting and bug fixing