Fix errors in previous commit, adds tests