Fix layout and optimize the code