Added controlling of file input, and refactoring