Fix code and documentation issues and improve performance of the `ports` tool