small refactoring & fix for #213
refactoring + code format