Simplify

The code structure has been simplified.
Further work here is still required.