Refactoring datalink layer functions