Some improvements & refactoring