Removed  hardcoding and added exception handling