security performance
Modified algorithm and Added error handling