Fix custom port detection
Starting porting on Ruby