roughly working, minus the bugs listed