Removing some redundant code and trying to speed up.