Merge with Blazenyan code

Cleaner solution