Code cleanup, and fixed some TODOs