edits to files and some refactoring