commented and rearranged for sanity