Refactoring code

Integration of most comments