Adds tests and fix