fix cdefs and various other redundencies
refactor inner loop into helper function
add another TODO
add another TODO