Greatly simplify the code