Refactors to get next available port