refactor fix for #199 to make it more readable