Add Several New Tests and Increase Safety of Code