Fixed tests and bugs