apdu refactoring plus tests