Refactor and exception handling.