Improved the code, adapted the behavior and tested on prod environment

Also fixed a lot of bugs.