TODO and bug fixes