Moved duplicated code to where it should be.