Changed variables, added exception handling