Removed some TODOs, refactoring, clean up, doc string