Add exception handling. Improve code readability.