minor refactors in function order, update comments.