Refactor controller to improve readability

Anonymous functions are transformed to named functions.

Signed-off-by: Davy Meers <davymeers@hotmail.com>