Adding unit tests, working through correctness (typed a ton by hand with no testing)