refactored, logging in file