Modifying some parts of code to prevent errors

+ new functionalities