added hooks to automatically handle ports
shortened scripts, deduplicated functionality