Rebased into seperate lib files.