Further code prettification.
using map for brevity.
catching a specific exception rather than all of them.