whole code reformated