A large piece of improvements and refactoring :gem: