added file saving, cleaned up