Changes suggested by Victor
Refactoring some code