added exception handling, etc.