Bug fixes in tests and reformatting