cleanup code and reformat