fixed import and added exception handling