refactoring a bit to make things work
Some changes