Fixes console.log to show correct port
Separates functions from exports for cleaner code. Adds some comments