Added max retry attempts for patch programming and updated code