Removed redundancy, improved if else construct
Added function for nil and empty check to remove redundancy
Added case with no exception raised