fixed a numbers of bugs