Changed the code to be more resemble to the original branch.