SWI handler and related code with tests