Refactored first fit, best fit and quick fit to different functions.