Unit tests and bug fixes for ATS