fixed logical errors