fixed tests

Fixed tests and also fixed small bugs revealed in fixed tests.