some bugs fixed, others noted with TODO