added some documentation
applied minor refactoring (switched if/else branch)