Functionalizing the new code. Added some TODOs.