Edited code to include Fletcher's update