Original port from ruby