rearange code and reindent