Improves error checks in constructor and adds tests