bug fixes and todo cleanup