started porting functions over from ruby gem