Fixed formatting and added comments

Fixed formatting and added comments as per review comments.