Simplify excessively complex code