WIP: moving perl functions over