refactoring code and file layout and splitting index file