Fix problems with Intellij, add exception handling.