finally fixed the obvious bugs