slight refactor and added tests. working now but needs a text formatting clean up