restructured and added comments