complete revamp to migrate to app fog. meanwhile make the code more standard