Reorganizes the code and adds the fix-bits function.