refactoring
added import resource
error handling