Add comments and Flatten code structure