Added logic for when an empty string is passed in and did some code refacotoring for stylistic issues