Implement the spec step by step

Some of the steps were optimized away.