Added dynamic parameter checking and several comments.