Adding Unit Tests, Also Refactor