added missing elements, begining refactoring