Commented and rearranged code