Some refactorization / bugs fixed

Backup before several refactorization