Reorder code and add some comments