finally fixed all bugs