Refactoring code according to the new port types and HAL API