Started revising the code with more linear types.