Add type signatures and other small stylistic improvements.