improved code

improved some parts of the code