Fix bug in mask, return correct port