refactored a bit the code
fixed other stuff