copied in existing functionality from the other repo