Revise TODO notes and move some code