Various edits

Refactoring, bug fixing etc.. See code.

Signed-off-by: Simone <hello@simonewebdesign.it>