Split long method and reformat code style