refactiring and fix