Changed variable names, added exception handling