New functions for #9 also cleaned up the existings ones.