Everything tested and works

added error checking