__hash__ method for factor class and reorder import statements