reorganized and added in comments