adding missing files and also a little refactoring