Redesigned lib into more functional