Some refactoring, substitute, etc.

Annotated pending bugs