added hooks to automatically handle ports