2-Advanced: Code quality improvment

improve code quality regarding PSR 1/2 style
add some comments and improve if/else statements to be more readable