light refactoring and bug fixes