extract some code from class app
do reformat