finished CAS refactor