simplified and structured controller code