Better exception handling, fix broken import