fixes and reformat code