Bug fixes and some TODOs